﻿@namespace BootstrapBlazor.Components
@typeparam TValue
@inherits ButtonUploadBase<TValue>

@if (IsShowLabel)
{
    <BootstrapLabel required="@Required" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
}
<div @attributes="@AdditionalAttributes" class="@ClassString" id="@Id">
    <Button class="@BrowserButtonClassString" IsDisabled="@IsUploadButtonDisabled" Icon="@BrowserButtonIcon" Text="@BrowserButtonText" />
    @if (ShowUploadFileList)
    {
        <div class="upload-body is-list">
            @foreach (var item in GetUploadFiles())
            {
                <div @key="item" class="@GetItemClassString(item)">
                    <i class="@GetFileFormatClassString(item)"></i>
                    <div class="fn">
                        <span>@item.GetFileName()</span>
                        <span>(@item.Size.ToFileSizeString())</span>
                    </div>
                    @if (GetShowProgress(item))
                    {
                        <i class="@LoadingIconString"></i>
                        <Progress Color="Color.Success" Height="2" Value="@item.ProgressPercent" />
                    }
                    else
                    {
                        <div class="upload-buttons">
                            @if (ShowDownloadButton)
                            {
                                <i class="@DownloadIconString" @onclick="() => OnClickDownload(item)"></i>
                            }
                            @if (item.Code == 0)
                            {
                                <i class="@ValidStatusIconString"></i>
                                @if (!IsDisabled)
                                {
                                    <i class="@DeleteIconString" @onclick:stopPropagation @onclick="@(e => OnFileDelete(item))"></i>
                                }
                            }
                            else
                            {
                                @if (!IsDisabled)
                                {
                                    <i class="@InvalidStatusIconString"></i>
                                    <i class="@DeleteIconString" @onclick:stopPropagation @onclick="@(e => OnFileDelete(item))"></i>
                                }
                            }
                        </div>
                    }
                </div>
            }
        </div>
    }
    <InputFile AdditionalAttributes="@GetUploadAdditionalAttributes()" OnChange="OnFileChange" />
</div>
